package edu.neusoft.yuejian_09.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.util.List;

import edu.neusoft.yuejian_09.R;
import edu.neusoft.yuejian_09.adapter.MyCollectUserListAdapter;
import edu.neusoft.yuejian_09.bean.User;
import edu.neusoft.yuejian_09.model.UserModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MyCollectUserActivity extends Activity {
    private Button collectTrain_button,
            collectUser_button,
            collectMaster_button,
            collectMatch_button,
            collectAct_button;
    private ImageView left;

    private int u_id;
    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_collect_list);
        initView();
        initEvents();
        initData();
    }
    private void initView(){

        collectUser_button=(Button) findViewById(R.id.collectUser_button);
        collectMaster_button=(Button) findViewById(R.id.collectMaster_button);
        collectMatch_button=(Button) findViewById(R.id.collectMatch_button);
        collectAct_button=(Button) findViewById(R.id.collectAct_button);
        left=(ImageView)findViewById(R.id.left);
        recyclerView=(RecyclerView) findViewById(R.id.my_collect);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局


    }
    private void initEvents(){

        //返回上一页
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });



        //跳转到用户
//        collectUser_button.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                Intent intent = new Intent(MyCollectUserActivity.this,MyCollectUserActivity.class);
//                startActivity(intent);
//            }
//        });

        //跳转到活动
        collectAct_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(MyCollectUserActivity.this,MyCollectActActivity.class);
                startActivity(intent);
            }
        });

        //跳转到大师
        collectMaster_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(MyCollectUserActivity.this,MyCollectMasterActivity.class);
                startActivity(intent);
            }
        });
        //跳转到比赛
        collectMatch_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(MyCollectUserActivity.this,MyCollectMatchActivity.class);
                startActivity(intent);
            }
        });
    }

    private void initData() {
        SharedPreferences sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        u_id = sp.getInt("user_id", 0);
//             Log.d("we","u_id");

        UserModel userModel = new UserModel();
        //发送请求
        Call<List<User>> call = userModel.getMyCollectUsers
                (u_id,"0");
        //2.处理结果
        call.enqueue(new Callback<List<User>>() {
            @Override
            public void onResponse(Call<List<User>> call, Response<List<User>> response) {
                List<User> data = (List<User>) response.body();  //获取数据
                recyclerView.setAdapter(new MyCollectUserListAdapter(MyCollectUserActivity.this, data));
            }

            @Override
            public void onFailure(Call<List<User>> call, Throwable t) {

            }

        });

    }

}
